package com.cdgc.web.controller;

import com.cdgc.web.pojo.VipTable;
import com.cdgc.web.service.VipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class VipController {
    @Autowired
    private VipService vipService;

    @RequestMapping("/queryAllVips")
    public ModelAndView queryAllVips(){
        List<VipTable> vipTableList = vipService.queryAllVips();
        ModelAndView mv = new ModelAndView();
        mv.addObject("vipTableList",vipTableList);
        mv.setViewName("viptable");
        return mv;
    }

    @RequestMapping("/addNewVip")
    public String addNewVip(VipTable vipTable){
        vipService.addNewVip(vipTable);
        return "redirect:/queryAllVips";
    }

    @RequestMapping("deleteVipById")
    public String deleteVipById(Integer id){
        vipService.deleteVipById(id);
        return "redirect:/queryAllVips";
    }

    @RequestMapping("toUpdateVipById")
    public ModelAndView toUpdateVipById(Integer id){
        VipTable vipTable = vipService.toUpdateVipById(id);
        ModelAndView mv = new ModelAndView();
        mv.addObject("vipTable",vipTable);
        mv.setViewName("UpdateVip");
        return mv;
    }

    @RequestMapping("/UpdateVip")
    public String UpdateVip(VipTable vipTable){
        vipService.UpdateVip(vipTable);
        return "redirect:/queryAllVips";
    }
}
